package com.hmy.observer;

import java.util.ArrayList;
import java.util.List;

public class PersonData implements Subject {
	private int height;
	private int weight;
	
	List<Observer> observers;
	
	public PersonData() {
		observers = new ArrayList<Observer>();
	}

	public void addObserver(Observer observer) {
		observers.add(observer);
	}

	public void removeObserver(Observer observer) {
		if (observers.indexOf(observer) != -1) {
			observers.remove(observer);
		}
	}

	public void notifyObservers(List<Observer> observers) {
		if (observers != null && observers.size() > 0) {
			for (Observer observer : observers) {
				observer.update(this.height, this.weight);
			}
		}
	}
	
	public void setPerson(int height, int weight) {
		this.height = height;
		this.weight = weight;
		notifyObservers(observers);
	}
	
	public int getHeight() {
		return height;
	}
	public void setHeight(int height) {
		this.height = height;
	}
	public int getWeight() {
		return weight;
	}
	public void setWeight(int weight) {
		this.weight = weight;
	}

}
